package com.szt.mobiles.inventory.common.biz;

import com.isoftstone.mis.ffair.comp.network.FFHttpClientComponent;
import com.szt.mobiles.inventory.common.constants.AppConstants;
import com.szt.mobiles.inventory.common.entity.BaseEntity;
import com.szt.mobiles.inventory.common.entity.ResponseEntity;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yanzhaodi on 2017/9/13.
 */

public class BaseBiz<T extends BaseEntity> {

    protected FFHttpClientComponent httpClientComponent;

    public BaseBiz() {
        httpClientComponent = new FFHttpClientComponent();

        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/x-www-form-urlencoded");

        httpClientComponent.addRequestHeaders(headers);
    }

    protected ResponseEntity<T> netError() {
        ResponseEntity<T> responseEntity = new ResponseEntity<>();
        responseEntity.resultCode = AppConstants.NET_ERROR;
        responseEntity.resultMsg = "网络异常";
        return responseEntity;
    }

    public void doCancel() {
        if (null != httpClientComponent) {
            httpClientComponent.cancel();
        }
    }

}
